﻿Imports System
Imports System.Data
Imports System.Windows.Forms
Imports MySql.Data.MySqlClient

Public Class yuangong_detail
    Dim conn As MySqlConnection
    Dim memoryImage As Bitmap

    '关闭窗口，返回员工查询
    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Me.Close()
        yuangongchaxun.Focus()
    End Sub
    '打印
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        print()
    End Sub
    '换卡
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim connstr As String
        Dim cmd As MySqlCommand
        Dim comm As String

        connstr = My.Settings.MysqlDB
        conn = New MySqlConnection(connstr)
        comm = String.Format("UPDATE zgb SET card_num='{0}' WHERE card_num='{1}'", _
                             CInt(InputBox("请输入卡号或刷卡", "卡号查询")), Me.IDnum.Text.ToString)

        cmd = New MySqlCommand(comm, conn)

        conn.Open()
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try
        conn.Close()

        MessageBox.Show("换卡成功")
    End Sub
    '更新
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim connstr As String
        Dim cmd As MySqlCommand
        Dim comm As String

        connstr = My.Settings.MysqlDB
        conn = New MySqlConnection(connstr)
        comm = String.Format("UPDATE zgb SET work_id='{0}',name='{1}',age='{2}',telephone='{3}' WHERE card_num='{4}'", _
                             Me.workid.Text.ToString, Me.name_worker.Text.ToString, Me.age.Text.ToString, Me.telephone.Text, Me.IDnum.Text.ToString)

        cmd = New MySqlCommand(comm, conn)

        conn.Open()
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try
        conn.Close()

        MessageBox.Show("更新数据成功")

    End Sub

    Private Sub yuangong_detail_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        'Me.photo.ImageLocation = photo.jpg

    End Sub

    '截屏函数
    Private Sub CaptureScreen()
        Dim myGraphics As Graphics = yuangong_print.CreateGraphics()
        Dim s As Size = yuangong_print.Size
        memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
        Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
        memoryGraphics.CopyFromScreen(yuangong_print.Location.X, yuangong_print.Location.Y, 0, 0, s)
    End Sub
    '打印函数
    Private Sub printDocument1_PrintPage(ByVal sender As System.Object, _
       ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
       PrintDocument1.PrintPage
        e.Graphics.DrawImage(memoryImage, 0, 0)
    End Sub
    '打印程序
    Private Sub print()
        yuangong_print.workpic.ImageLocation = me.photo.ImageLocation
        yuangong_print.workname.Text = me.name_worker.Text
        yuangong_print.worknum.Text = me.workid.Text
        yuangong_print.Show()
        MessageBox.Show("正在打印，请稍后")
        CaptureScreen()
        PrintDocument1.Print()
        yuangong_print.Close()
    End Sub
End Class
